<template>
  <div>
    <el-cascader
      v-model="value"
      :options="options"
      :props="props"
      @change="handleChange"
    />
  </div>
</template>
<script>
import { getDepartment } from '@/api/department'
import { toTree } from '@/utils/index'
export default {
  props: {
    value: { // 回显  11
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      props: {
        label: 'name',
        value: 'id',
        children: 'children'
      },
      options: [{}]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleChange(list) { // 级联收集的数据
      console.log(list, ':-------------')// [1,4,11]
      // 将最后一个部门的id传给父组件
      this.$emit('sendDeprtId', list[list.length - 1])
    },
    async getList() { // 获取组织数据 渲染给级联选择器
      const res = await getDepartment()
      this.options = toTree(res.data, 0)
    }
  }

}
</script>
<style lang="scss">

</style>
